package com.ternnetwork.oa.utils;

import com.ternnetwork.commons.utils.DateUtils;
import com.ternnetwork.oa.enums.work.EventRemindTime;

import java.util.Date;

public class EventRemindTimeUtils {


    public static Date convertRemindTime(String  start, String remindTime) {
        Date parseDate= DateUtils.parseDate(start, DateUtils.FORMAT_DATE_TIME_DEFAULT);
        return convertRemindTime(parseDate,EventRemindTime.valueOf(remindTime));
    }

    public static Date convertRemindTime(Date start, EventRemindTime remindTime) {

        if (EventRemindTime.BEFORE_TEN_MINUTE.equals(remindTime)) {
            Long newTime = start.getTime() - 10 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_HALF_HOUR.equals(remindTime)) {
            Long newTime = start.getTime() - 30 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_ONE_HOUR.equals(remindTime)) {
            Long newTime = start.getTime() - 60 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_ONE_DAY.equals(remindTime)) {
            Long newTime = start.getTime() - 24 * 60 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_THREE_DAY.equals(remindTime)) {
            Long newTime = start.getTime() - 3*24 * 60 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_FIVE_DAY.equals(remindTime)) {
            Long newTime = start.getTime() - 5*24 * 60 * 60 * 1000L;
            return new Date(newTime);
        }
        if (EventRemindTime.BEFORE_TEN_DAY.equals(remindTime)) {
            Long newTime = start.getTime() -10*24 * 60 * 60 * 1000L;
            return new Date(newTime);
        }
        return start;
    }
}
